﻿Public Class maslocationd
    Private LOCATION = Nothing
    Private LOCATENAME = Nothing
    Private STATUS = Nothing
    Private selectMaslocationd = "SELECT `location` as 'รหัสสถานที่เก็บยา',`locatename` as 'สถานที่เก็บยา',`status` as 'สถานะการเปิดใช้งาน' FROM maslocationd"
    'Private selectMasgrpdrg = "SELECT GDCODE, GRPDRG, convert(bit, [STATUS]) FROM MASGRPDRG"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property LOCATION_ As Integer
        Get
            Return LOCATION
        End Get
        Set(value As Integer)
            LOCATION = value
        End Set
    End Property

    Property LOCATENAME_ As String
        Get
            Return LOCATENAME
        End Get
        Set(value As String)
            LOCATENAME = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMaslocationd_ As String
        Get
            Return selectMaslocationd
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMaslocationdData()
        If TypeOf LOCATENAME Is String Then
            If connect.GetTable("SELECT location FROM maslocationd WHERE locatename = '" & LOCATENAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลกลุ่มยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO maslocationd (locatename, status) VALUES ('" & LOCATENAME & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลสถานที่เก็บยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMaslocationdData()
        If TypeOf LOCATENAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE maslocationd SET locatename = '" & LOCATENAME & "', status = '" & STATUS & "' WHERE location = '" & LOCATION & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลสถานที่เก็บยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class